<?php
namespace app\shop\controller\v1;
use think\Loader;
use think\Db;
use app\shop\model\Order;

class Index extends Init
{
	private $IndexModel;


	protected function _initialize()
	{
		parent::_initialize();
		$this->IndexModel = Loader::model('Index');
	}

	//首页分类和标签
	public function index()
	{
		$param = input('post.');
		//获取顶级分类
		$data['category'] = $this->IndexModel->getCategoryData(1);
		//获取所有标签
		$data['title'] = $this->IndexModel->getTitleData();
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}

	//标签下商户列表
	public function LabelList(){
		$param = input('post.');
		$result = $this->validate($param, 'SellerValidate.label');
			if (true !== $result) {
				return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
			}
		$page = isset($param['page']) ? ($param['page'] == false ? 1 : $param['page'] ) : 1;
		$orll_page = config('paginate.list_rows');
		$data = $this->IndexModel->getLabelListData($param,$page,$orll_page);
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}

	//分类下商户列表
	public function CategoryList(){
		$param = input('post.');
		$result = $this->validate($param, 'SellerValidate.category');
			if (true !== $result) {
				return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
			}
		$page = isset($param['page']) ? ($param['page'] == false ? 1 : $param['page'] ) : 1;
		$orll_page = config('paginate.list_rows');
		$data = $this->IndexModel->getCategoryListData($param,$page,$orll_page);
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}

	// 显示附近商户
	public function nearbySeller(){
		$param = input('post.');
		$page = isset($param['page']) ? ($param['page'] == false ? 1 : $param['page'] ) : 1;
		$orll_page = config('paginate.list_rows');
		$data = $this->IndexModel->getNearbySellerData($param,$page,$orll_page);
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}
	
	//获取商户详情
	public function sellerDetail(){
		$param = input('post.');
		$result = $this->validate($param, 'SellerValidate.seller');
			if (true !== $result) {
				return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
			}
		$data = $this->IndexModel->getSellerListData($param);
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}

	//搜索商品
	public function SearchSeller(){
		$param = input('post.');
		$result = $this->validate($param, 'SellerValidate.search');
			if (true !== $result) {
				return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
			}
		$page = isset($param['page']) ? ($param['page'] == false ? 1 : $param['page'] ) : 1;
		$orll_page = config('paginate.list_rows');
		$data = $this->IndexModel->getSearchSellerData($param,$page,$orll_page);
		return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
	}
}